# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# pyojo                                           Copyright (c) 2011 nabla.net
# ----------------------------------------------------------------------------


from pyojo.all import *




def _menu():
    return (dijit.DropDownMenuItem("Menu_debug", 
                                   "Desarrollo", 
                                   iconClass="pyojoIconAccept"
                                   ).add("Menu_tools"),
            dijit.MenuItem(label="Explorador", 
                           id="menu_dev_file", 
                           iconClass=ICON["Closed"]).add("Menu_debug"),
            dijit.MenuItem(label="Configuración", 
                           id="menu_dev_cfg", 
                           iconClass=ICON["Configure"]).add("Menu_debug"),
            dijit.MenuItem(label="Sesión", 
                           id="menu_dev_session", 
                           iconClass=ICON["Leaf"]).add("Menu_debug"),
            dijit.MenuItem(label="Errores", 
                           id="menu_dev_err", 
                           iconClass=ICON["Error"]).add("Menu_debug"),
            
            dojo.on("menu_dev_file", "click", js.recall("data/tree_nav")),
            dojo.on("menu_dev_cfg", "click", js.recall("dev/server/config")),
            dojo.on("menu_dev_session", "click", js.recall("dev/server/session")),
            dojo.on("menu_dev_err", "click", js.recall("dev/server/err")), 
           ) 



def _demo_item(name, script, menu="dojo"):
    
    menuid = "menu_%s_%s" % (menu, name.replace(" ", "_"))
    return (dijit.MenuItem(label=name, 
                           id=menuid, 
                           iconClass=ICON["Leaf"]).add("menu_%s" % menu),
            
            dojo.on(menuid, "click", js.load(script)))

def _demo():
    return (dijit.DropDownMenuItem("menu_demo", 
                                   "Demo", 
                                   iconClass=ICON["Closed"]
                                   ).add("Menu_tools"),
            dijit.DropDownMenuItem("menu_dojo", 
                                   "Dojo Toolkit",
                                   iconClass=ICON["Closed"]
                                   ).add("menu_demo"),
            dijit.DropDownMenuItem("menu_dijit", 
                                   "Dijit Widgets", 
                                   iconClass=ICON["Closed"]
                                   ).add("menu_demo"),
            
        _demo_item("Icons", 
                   "demo/dojo/icons.js", "dojo"),
        
        _demo_item("Form", 
                   "demo/dijit/form/Form.js", "dijit"),
        _demo_item("Form inputs", 
                   "demo/dijit/form/inputs.js", "dijit"),
        _demo_item("TextBox", 
                   "demo/dijit/form/TextBox.js", "dijit"),
        _demo_item("NumberTextBox", 
                   "demo/dijit/form/NumberTextBox.js", "dijit"),
        _demo_item("TimeTextBox", 
                   "demo/dijit/form/TimeTextBox.js", "dijit"),
        _demo_item("DateTextBox", 
                   "demo/dijit/form/DateTextBox.js", "dijit"),
        _demo_item("Button", 
                   "demo/dijit/form/Button.js", "dijit"),
        _demo_item("DropDownButton", 
                   "demo/dijit/form/DropDownButton.js", "dijit"),
        _demo_item("ComboButton", 
                   "demo/dijit/form/ComboButton.js", "dijit"),
        _demo_item("ToggleButton", 
                   "demo/dijit/form/ToggleButton.js", "dijit")
           ) 


def _dev():
    panel = layout.ContentPane("dev", 
                               title="Desarrollo", 
                               content ="<button id=\"b1\"></button>")
    #panel.add("TABS")
    panel.call_method_of("TABS", "addChild")
    
    return ( panel,
             form.Button(label = 'Aceptar', ID='b1', iconClass="pyojoIconAccept")
             )
# ----------------------------------------------------------------------------

def GET(request):
    code =  js.Require(
                      _menu(),
                      _demo(),
                      _dev(),
                      "status('Debug Interface ready.');",
                      
                      ).requires("pyojo/gui_tree")


    #return define_run(code)
    return js.Define(run=code).requires("dojo/domReady!")


